package com.ayuku.commons;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * @author putu kusuma <putukn@gmail.com>
 *
 */
public class HelpWindow extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Browser broser;


	public HelpWindow(Shell parent, int style) {
		super(parent, style);
	}

	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent,parent.getStyle());

			FormLayout dialogShellLayout = new FormLayout();
			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();
			dialogShell.setSize(554, 521);
			{
			
				FormData button1LData = new FormData();
				button1LData.width = 49;
				button1LData.height = 21;
				button1LData.left =  new FormAttachment(0, 1000, 7);
				button1LData.top =  new FormAttachment(0, 1000, 7);
		
			}
			{
				FormData broserLData = new FormData();
				broserLData.width = 532;
				broserLData.height = 441;
				broserLData.top =  new FormAttachment(0, 1000, 42);
				broserLData.left =  new FormAttachment(0, 1000, 7);
				broserLData.bottom =  new FormAttachment(1000, 1000, -11);
				broserLData.right =  new FormAttachment(1000, 1000, -7);
				broser = new Browser(dialogShell, SWT.BORDER);
				broser.setLayoutData(broserLData);
				
				
				File file = new File("./" + File.separatorChar+"docs/index.html");
				file = file.getAbsoluteFile();  
				
				broser.setUrl(file.toString());
				//broser.setUrl("C:\\Downloads\\Software\\easypint_1.01_bin\\readme.html");
				broser.refresh();
				
			}
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			
		}
	}
	
}
